//
//  JKLTabBarController.m
//  JKL
//
//  Created by 李善武 on 16/5/25.
//  Copyright © 2016年 李善武. All rights reserved.
//

#import "JKLTabBarController.h"
#import "JKLHomeTableViewController.h"
#import "JKLHisViewController.h"
#import "JKLMeTableViewController.h"
#import "JKLOrderTableViewController.h"
#import "JKLTabBar.h"
#import "UIImage+Render.h"
@interface JKLTabBarController ()

@end

@implementation JKLTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupAllChildVC];
    [self setupTabBar];
    [self setupAllTitleButton];
}

// 页面底部tabBar所对应的所有控制器
- (void)setupAllChildVC{
    
    // 首页
    JKLHomeTableViewController *homeTabVC = [[JKLHomeTableViewController alloc]init];
    UINavigationController *homeNavVC = [[UINavigationController alloc]initWithRootViewController:homeTabVC];
    [self addChildViewController:homeNavVC];
    
    // 医院
    JKLHisViewController *hisVC = [[JKLHisViewController alloc]init];
    UINavigationController *hisNavVC = [[UINavigationController alloc]initWithRootViewController:hisVC];
    [self addChildViewController:hisNavVC];
    
    // 订单
    JKLOrderTableViewController *orderTabVC = [[JKLOrderTableViewController alloc]init];
    UINavigationController *orderNavVC = [[UINavigationController alloc]initWithRootViewController:orderTabVC];
    [self addChildViewController:orderNavVC];
    
    // 我的
    JKLMeTableViewController *meTabVC = [[JKLMeTableViewController alloc]init];
    meTabVC.view.backgroundColor = [UIColor redColor];
    UINavigationController *meNavVC = [[UINavigationController alloc]initWithRootViewController:meTabVC];
    [self addChildViewController:meNavVC];
    
}

// 设置所有按钮标题
- (void)setupAllTitleButton{
   
    // 首页
    UINavigationController *nav0 = self.childViewControllers[0];
    nav0.tabBarItem.title = @"首页";
    nav0.tabBarItem.image = [UIImage imageNameWithOriginal:@"main_unselected"];
    nav0.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"main_selected"];
    
    // 医院
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"医院";
    nav1.tabBarItem.image = [UIImage imageNameWithOriginal:@"hospital_unselected"];
    nav1.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"hospital_selected"];
    
    // 订单
    UINavigationController *nav2 = self.childViewControllers[2];
    nav2.tabBarItem.title = @"订单";
    nav2.tabBarItem.image = [UIImage imageNameWithOriginal:@"discover_unselected"];
    nav2.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"discover_selected"];
    
    // 我的
    UINavigationController *nav3 = self.childViewControllers[3];
    nav3.tabBarItem.title = @"我的";
    nav3.tabBarItem.image = [UIImage imageNameWithOriginal:@"user_unselected"];
    nav3.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"user_selected"];
    
}

// 设置自定义的tabBar
- (void)setupTabBar{
   
    JKLTabBar *tabBar = [[JKLTabBar alloc]init];
    [self setValue:tabBar forKey:@"tabBar"];
}
@end
